package com.akiokevin.plantyourlife;

import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.akiokevin.plantyourlife.activity.ScheduleActivity;

public class PlantYourLifeActivity extends Activity {
	
	private Button mScheduleButton;
	private ImageView mPlantImage;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Buttons settings
        mScheduleButton = (Button) findViewById(R.id.button_schedule);
        mScheduleButton.setOnClickListener(new View.OnClickListener() {
        	@Override
        	public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(), ScheduleActivity.class);
				startActivity(intent);
				}
        });
        
        // Image settings
        mPlantImage = (ImageView)findViewById(R.id.img_plant);
        Bitmap sample = getBitmapFromAsset("img/ShouldComeFromServer_x_y.png");
        mPlantImage.setImageBitmap(sample);
    }
    
    // Helper to parse image file from given URL
    // URL should be generated to reflect the collected statistics
    private Bitmap getBitmapFromAsset(String url) {
    	// TODO should get image from server instead of asset in the future
    	Bitmap bitmap = null;
        AssetManager assetManager = getAssets();
        try {
	        InputStream istr = assetManager.open(url);
	        bitmap = BitmapFactory.decodeStream(istr);
        } catch(Exception e) {
        	System.out.println("InputStream fail");
        }
        return bitmap;
    }
}
